home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-05-01 | 8.7 KB | 274 lines | [TEXT/MPS ] |
- % ---------------------------------------------------------------------------
- % Class MACProcessMGR
- %
- % Part of the Lund Software interface to Macintosh Toolbox
- % MACProcessMGR is part of the programming interface.
- % Processes are used to capture events that are directed to
- % a window. The MACProcessMGR are receiving the events from the
- % Mac and distributes them to the concerned window.
- % For each Window - create also a MACProcess and hook it to the window
- % by calling RegisterProcess.
- %
- % 890406/Boris Magnusson
- % 890429/Boris Magnusson Made registerd Window selected
- % ---------------------------------------------------------------------------
- External class macPoint="::SInterfaces:macPoint";
- External class macRect="::SInterfaces:macRect";
- External class macEvent="::SInterfaces:macEvent";
- External class MacProcess="::SInterfaces:MacProcess";
- External class MacWindowMgr="::SInterfaces:MacWindowMgr";
- External class MacEventMgr="::SInterfaces:MacEventMgr";
- External class macToolConst="::SInterfaces:macToolConst";
- External class macUtilities="::SInterfaces:macUtilities";
- MacWindowMgr class MacProcessMGR;
- begin
- ref(macToolConst) TConst; ! Shared by each Process ;
- ref(macUtilities) Util; ! also shared by processes ;
- ref(MacEventMgr) EventMgr;
- Boolean terminate; ! set to true by 'stop' to make 'Run' quit. ;
-
- % -- system xxx moved from toolboxDesk -- used only from processMGR --
- % -- copied also to macProcessMgr ------
- % PROCEDURE SystemClick(theEvent: EventRecord; theWindow: WindowPtr);
- PROCEDURE SystemClick(theEvent, theWindow);
- ref(MacEvent) theEvent;
- ref(MACWindow) theWindow;
- EventMgr.ToolboxSystemClick(theEvent.what, theWindow.WindowPtr);
-
- % PROCEDURE SystemTask;
- PROCEDURE SystemTask;
- EventMgr.ToolboxSystemTask;
- % ------------------------------------------
-
- ! Return reference to the process controlling the Active window. ;
- ref(macProcess) procedure CurrentProcess;
- begin
- currentprocess:- if ActivePN=/=None then ActivePN.P
- else none;
- end;
-
- ! Register a Process as controlling a Window ;
- procedure RegisterProcess(P,W); ref(MacProcess) P; ref(MacWindow) W;
- begin
- ActivePN:-new ProcessNotice(P,W);
- P.Util:-Util;
- P.TConst:-TConst;
- SelectWindow(ActivePN.W);
- call(ActivePN.P); ! -- run initialization code of Process, ;
- ! -- up to first getnextEvent. ;
- ActivePN.into(EventWaitQ);
- end--- Controlling Window ---;
-
- ! register a Process as controlling the Menu bar;
- procedure RegisterMenuProcess(p); ref(MacProcess) P;
- begin
- MenuController:-P;
- P.Util:-Util;
- P.TConst:-TConst;
- call(MenuController); ! perform inital actions ;
- end;
-
- ! register a Process as controlling the System Window;
- procedure RegisterSystemProcess(p); ref(MacProcess) P;
- begin
- SystemController:-P;
- P.Util:-Util;
- P.TConst:-TConst;
- call(SystemController); ! perform inital actions;
- end;
-
- ! remove a process from the system ;
- procedure Kill(toKill); ref(macProcess) toKill;
- begin
- ref(processNotice) PN;
- PN:-convertPtoPN(toKill);
- PN.out;
- end -- kill -- ;
-
- ! Make 'RUN' Terminate next time somebody leaves control ;
- Procedure Stop;
- Terminate:=true;
-
- ! - Get events and dispatch to controler of 'hit' window. - ;
- Procedure Run;
- begin
- Boolean Gotten_an_Event,Inside;
- integer code; ! Hit region encoding ;
- integer v_h,height,width;
- ref(MacPoint) ThePoint;
- ref(MacEvent) TheEvent;
- ref(MacWindow) TheWindow;
- ref(ProcessNotice) PN;
- ref(macRect) ScreenBounds;
- Terminate:=false;
- TheEvent:- new MacEvent;
- ThePoint:- new MacPoint;
- ScreenBounds:-new MACrect;
- getScreenRect(ScreenBounds);
- while not Terminate do
- begin
- Gotten_an_Event:=EventMgr.getnextEvent(-1,theEvent); ! all events ;
- if Gotten_an_Event then
- begin
- if theEvent.what=TConst.mousedown then
- begin
- thePoint.v:=theEvent.point_v;
- thePoint.h:=theEvent.point_h;
- code:=FindWindow(thePoint,theWindow);
- if code =Tconst.inSysWindow then
- begin
- if systemController=/=none and then
- util.bitand(Util.BitShift(1,theEvent.what) ,
- systemController.CurrentMask )<>0 then
- begin
- SystemController.CurrentEvent:-theEvent;
- Call(SystemController);
- end
- else
- begin
- Systemclick(TheEvent,TheWindow);
- end -- system - click -- ;
- end -- in sys Window --
- else if code =Tconst.inMenuBar then
- begin
- if MenuController =/= none and then
- util.bitand(Util.BitShift(1,theEvent.what) ,
- Menucontroller.CurrentMask )<>0 then
- begin
- MenuController.CurrentEvent:-theEvent;
- MenuController.Currentfindresult:=code;
- Call(MenuController);
- end;
- end - in menu bar -
- else
- begin ! -- mouse down in user window --;
- PN:-ConvertToPN(theWindow);
- if PN==none then
- ! Ignore event for some unknown Window ;
- else if PN=/=ActivePN then
- begin
- ActivePN:-PN; ! - Notice of current Window.;
- SelectWindow(PN.W); ! - First hit just selects - ;
- if Code=Tconst.inDrag then ! - and possily drags ! ;
- PN.W.DragWindow(thePoint,ScreenBounds);
- end -- first mused-down activates -
- else if Code=Tconst.inDrag then
- PN.W.DragWindow(thePoint,ScreenBounds)
- else if Code=Tconst.inGrow then
- begin
- v_h:=PN.W.GrowWindow(thePoint,ScreenBounds);
- height:=util.hiword(v_h);width:=util.loword(v_h);
- PN.P.doSize(width,height);
- end -- User Window re-size --
- else if Code=Tconst.ingoAway then
- begin
- inside:=PN.W.TrackGoAway(thePoint);
- if inside then PN.P.doGoAway;
- end -- User Window go-away --
- else if Util.bitand(Util.BitShift(1,theEvent.what) ,
- PN.P.CurrentMask )<>0 then
- PN.into(ReadyQ) ! MouseDown event for user Window ;
- else
- ! Discard Disabled Mouse down Event ; ;
- end -- Muse down in user Window -- ;
- end -- Mouse-down Event --
- else if theEvent.what=TConst.keyDown and then
- util.bitAnd(theEvent.modifiers,TConst.cmdKey)<>0 then
- begin
- MenuController.CurrentEvent:-theEvent;
- MenuController.Currentfindresult:=code;
- Call(MenuController);
- !!! if no hit then ...;
- end - Meta key -
- else if theEvent.what=TConst.updateEvt or else
- theEvent.what=TConst.ActivateEvt then
- begin
- theWindow:-ConvertToWindow(theEvent.Message);
- PN:-ConvertToPN(theWindow);
- if PN==none then
- begin
- ! Ignore event for some unknown Window ;
- end
- else if Util.bitand(Util.BitShift(1,theEvent.what) ,
- PN.P.CurrentMask )<>0 then
- begin
- PN.W.Setport; ! Temporarily make updated Window ;
- ! the port for Quickdraw ;
- PN.P.CurrentEvent:-theEvent;
- PN.P.CurrentFindResult:=Code;
- PN.W qua macQuickdraw.TRAP
- .ToolboxGlobaltoLocal(theEvent.point_v);
- Call(PN.P);
- if PN.P.Terminate then
- PN.out;
- FrontWindow.Setport; ! revert to Active Window ;
- end;
- end -- Upate/Activate event --
- else
- Begin ! --- all other events go to Previous window ;
- if ActivePN=/=none and then
- Util.bitand(Util.BitShift(1,theEvent.what) ,
- ActivePN.P.CurrentMask )<>0 then
- ActivePN.into(ReadyQ);
- End - other event for Old Window -;
- end - gotten an event --
- else
- begin ! -- send NULL event to active process if enabled -- ;
- if ActivePN=/=none and then
- Util.bitand(Util.BitShift(1,Tconst.NullEvent) ,
- ActivePN.P.CurrentMask )<>0 then
- begin
- ActivePN.into(ReadyQ);
- theEvent.what:=Tconst.NullEvent;
- end;
- end - null event -- ;
- while not readyQ.Empty do ! currently at most one in ReadyQ;
- begin
- PN:-ReadyQ.first;
- PN.out;
- PN.P.CurrentEvent:-theEvent;
- PN.P.CurrentFindResult:=Code;
- PN.W qua macQuickdraw.TRAP
- .ToolboxGlobaltoLocal(theEvent.point_v);
- Call(PN.P);
- if not PN.P.Terminate then
- PN.into(EventWaitQ);
- end - run the process of known window - ;
- end - while - ;
- end --- Run --- ;
-
- ! -------------- Local routines ------------ ;
- Link class ProcessNotice(P,W); ref(MacProcess) p; ref(MacWindow) W;;
-
- ref(Head) ReadyQ,EventWaitQ;
- ref(MacProcess) MenuController, SystemController;
- ref(ProcessNotice) ActivePN;
-
- ref(ProcessNotice) procedure ConvertToPN(aWindow);
- ref(MACWindow) aWindow;
- begin
- ref(ProcessNotice) pPN;
- pPN:-EventWaitQ.first;
- while pPN=/=none and then pPN.W=/=aWindow do
- pPN:-pPN.suc;
- ConvertToPn:-pPN;
- end -- ConvertToPN --;
-
- ref(ProcessNotice) procedure ConvertPToPN(aP);
- ref(MACprocess) aP;
- begin
- ref(ProcessNotice) pPN;
- pPN:-EventWaitQ.first;
- while pPN=/=none and then pPN.P=/=aP do
- pPN:-pPN.suc;
- ConvertPToPn:-pPN;
- end -- ConvertToPN --;
-
- ReadyQ :- new Head;
- EventWaitQ:- new Head;
- EventMgr:-new MacEventMgr;
- TConst:-new macToolConst;
- Util:- new macUtilities;
- SystemController:-none; ! :- new DefaultSystemController;
- end --- Process MGR --- ;
-